package com.qianyu.project.mapper.provider.smj;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.ObjectUtils;

import java.util.Map;

public class smjFragmentaryProvider {
    //获取零星劳务单列表
    public String ListFragmentary(IPage<Map<String, Object>> page, Map<String, String> params){
        return new SQL() {
            {
                SELECT("f.*, e.name,pi.project_name");
                FROM("fragmentary f");
                LEFT_OUTER_JOIN("project_info pi on f.p_id=pi.id");
                LEFT_OUTER_JOIN("emp e on f.handler_id = e.id");
                if (!ObjectUtils.isEmpty(params.get("id"))){
                    WHERE("f.id = '"+params.get("id")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("p_id"))){
                    WHERE("f.p_id = '"+params.get("p_id")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("empId"))){
                    WHERE("f.handler_id = '"+params.get("empId")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("start_date"))){
                    WHERE("f.apply_date >= '"+params.get("start_date")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("end_date"))){
                    WHERE("f.apply_date <= '"+params.get("end_date")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("type"))){
                    WHERE("f.type = '"+params.get("type")+"'");
                }
            }
        }.toString();
    }
}
